package com.operation.net.controller;

import com.operation.net.common.ApiRestResponse;
import com.operation.net.model.Link;
import com.operation.net.model.SystemInfo;
import com.operation.net.service.impl.InterfaceService;
import com.operation.net.service.impl.SystemService;
import com.operation.net.topology.TopologyDiscovery;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Set;

@RestController
@RequestMapping("/config")
public class SystemController {
    @Autowired
    private SystemService systemService;

    @Autowired
    private InterfaceService interfaceService;

    @Autowired
    TopologyDiscovery topologyDiscovery;

    @PostMapping("add")
    public ApiRestResponse connectivelies(@RequestBody SystemInfo systemInfo) throws Exception {
        try {
            systemService.getBase(systemInfo.getIp());
        } catch (Exception e) {
            e.printStackTrace();
        }
        interfaceService.GetInterInfo(systemInfo.getIp());
        topologyDiscovery.deviceInterfaceMac();
        topologyDiscovery.neighborMac();
        topologyDiscovery.connectOfAll();
        topologyDiscovery.initConnectively();
        return ApiRestResponse.success();

    }


}
